package com.example.user.customviewdemo.apidemo.animation;

import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.example.user.customviewdemo.R;

import butterknife.Bind;
import butterknife.ButterKnife;

public class BouncingBallsActivity extends AppCompatActivity {

    @Bind(R.id.container)
    LinearLayout container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bouncing_balls);
        ButterKnife.bind(this);

        container.addView(new MyAnimationView(this));
    }


    static class MyAnimationView extends View{

        public MyAnimationView(Context context) {
            super(context);
            init();
        }

        public MyAnimationView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }

        public MyAnimationView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init();
        }

        public void init(){
           ValueAnimator animator = ObjectAnimator.ofInt(this,"backgroundColor", Color.RED,Color.BLUE);
            animator.setDuration(3000);
            animator.setEvaluator(new ArgbEvaluator());
            animator.setRepeatCount(ValueAnimator.INFINITE);
            animator.setRepeatMode(ValueAnimator.REVERSE);
            animator.start();

        }

        public void addBall(float x,float y){
            OvalShape shape = new OvalShape();
            shape.resize(50f,50f);
            ShapeDrawable drawable = new ShapeDrawable(shape);


        }
    }
}
